package com.bstek.bdf2.core.context;

import org.apache.commons.lang.StringUtils;

import com.bstek.dorado.core.Configure;
import com.bstek.dorado.core.io.ResourceLoader;
import com.bstek.dorado.core.pkgs.PackageConfigurer;

/**
 * core的包配置加载实现类
 * @author Jacky.gao
 * @since 2013年5月21日
 */
public class CoreContextLocationConfigurer implements PackageConfigurer {

	/**
	 * bdf4-core的一些核心配置注入
	 * @param resourceLoader
	 * @return
	 * @throws Exception
	 */
	@Override
	public String[] getPropertiesConfigLocations(ResourceLoader resourceLoader) throws Exception {
		String coreProperties="classpath:com/bstek/bdf2/core/config/bdf2.core.properties";
		String ormProperties="classpath:com/bstek/bdf2/core/config/bdf2.orm.properties";
		return new String[]{coreProperties,ormProperties};
	}

	/**
	 * 包路径下的上下文配置加入
	 * @param resourceLoader
	 * @return
	 * @throws Exception
	 */
	@Override
	public String[] getContextConfigLocations(ResourceLoader resourceLoader) throws Exception {
		String contextCore="classpath:com/bstek/bdf2/core/config/bdf2-core-configs.xml";
		String contextSecurity="classpath:com/bstek/bdf2/core/config/bdf2-security-configs.xml";
		String contextOrm="classpath:com/bstek/bdf2/core/config/bdf2-orm-configs.xml";
		String dataSourceContextLocation=Configure.getString("bdf2.dataSourceContextLocation");
		if(StringUtils.isNotEmpty(dataSourceContextLocation)){
			return new String[]{contextCore,contextSecurity,contextOrm,dataSourceContextLocation};
		}else{
			return new String[]{contextCore,contextOrm,contextSecurity};
		}
	}

	/**
	 * servlet上下文配置加入
	 * @param resourceLoader
	 * @return
	 * @throws Exception
	 */
	@Override
	public String[] getServletContextConfigLocations(ResourceLoader resourceLoader) throws Exception {
		return new String[]{"classpath:com/bstek/bdf2/core/config/bdf2-core-servlet-context.xml"};
	}
}
